package de.devisnik.eidle.flashlight.command;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.handlers.HandlerUtil;

import de.devisnik.eidle.EidleViewPart;
import de.devisnik.eidle.flashlight.MultiFlashlightScreen;

public abstract class FlashCommandHandler extends AbstractHandler implements IHandler {

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
		if (!(activePart instanceof EidleViewPart))
			return null;
		EidleViewPart eidlePart = (EidleViewPart) activePart;
		MultiFlashlightScreen flashScreen = (MultiFlashlightScreen) eidlePart.getCurrentScreen();
		executeCommand(flashScreen);
		return null;
	}

	protected abstract void executeCommand(MultiFlashlightScreen flashScreen);
}
